package ecitys.gcs


import ecitys.types.Money

class CalculoPorIndice extends CalculoVerba {
	
	Indice indice
	Verba verba
	
	@Override
	static Money doCalculo(){
		  Money.newMoneyFromReal(getValueFromIndice())
	}
	
	Money getValueFromIndice(){
		
		def Money result = indice.getCurrentValue()
		
		if (verba.fatorDeMultiplicacao > 0)
			result = result * verba.fatorDeMultiplicacao
			
		if (verba.fatorDeDivisao > 0)
		   result = result / verba.fatorDeDivisao
		
		if (verba.percentual > 0)
		   result = result * (percentual/100)
			
		return result

	}
	
	public CalculoPorIndice(Indice indice, Verba verba) {
		super();
		this.indice = indice;
		this.verba = verba
	}



	String toString() {
		// TODO Groovy Auto-generated method stub
		// Only partially implemented. Perform organize imports
		// to properly import parameter and return types
		indice.toString()
	}
	
	static transients = ['indice','verba','valueFromIndice']
	
	static mapping = {
		table schema:"gcs"
	}
	
    static constraints = {
		indice(blank:false, nullable:false)
    }
}
